package org.example.demojdbc.mapper;

import org.example.demojdbc.dox.Address;
import org.example.demojdbc.dox.User;
import org.example.demojdbc.dto.AddressUserDTO;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
@Repository
public class AddressRowMapper implements RowMapper<AddressUserDTO> {
    @Override
    public AddressUserDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
        User user=User.builder()
                .id(rs.getString("u.id"))
                .name(rs.getString("u.name"))
                .createTime(rs.getObject("create_time", LocalDateTime.class))
                .build();
        Address address= Address.builder()
                .id(rs.getString("a.id"))
                .detail(rs.getString("a.detail"))
                .userId(rs.getString("a.user_id"))
                .createTime(rs.getObject("create_time", LocalDateTime.class))
                .build();

        return AddressUserDTO.builder()
                .user(user)
                .address(address)
                .build();
    }
}
